# Project
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(rapidcsv VERSION 1.0 LANGUAGES CXX)
set (CMAKE_CXX_STANDARD 11)
if(MSVC)
  if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
    string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  else()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
  endif()
else()
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wpedantic -Wshadow -Wpointer-arith \
                       -Wcast-qual -Wno-missing-braces -Wswitch-default -Wcast-align -Wunreachable-code \
                       -Wundef -Wuninitialized")
endif()

include(CheckIncludeFileCXX)
check_include_file_cxx(codecvt HAS_CODECVT)
if(HAS_CODECVT)
  add_definitions(-DHAS_CODECVT)
endif()

# Ccache
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
  message(STATUS "Found ccache")
  set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()

# Test init
include(CTest)
enable_testing()
include_directories("src")
set(LIB_HEADERS "src/rapidcsv.h")
set(TEST_HEADERS "tests/unittest.h")

# Test macro add_perf_test
macro (add_perf_test testname)
  add_executable(${testname} tests/${testname}.cpp)
  add_test(NAME ${testname} CONFIGURATIONS perf Release COMMAND "${PROJECT_BINARY_DIR}/${testname}")
endmacro (add_perf_test)

# Test macro add_unit_test
macro (add_unit_test testname)
  add_executable(${testname} tests/${testname}.cpp)
  add_test(NAME ${testname} CONFIGURATIONS unit Debug COMMAND "${PROJECT_BINARY_DIR}/${testname}")
endmacro (add_unit_test)

# Unit tests
if(1)
  add_unit_test(test001)
  add_unit_test(test002)
  add_unit_test(test003)
  add_unit_test(test004)
  add_unit_test(test005)
  add_unit_test(test006)
  add_unit_test(test007)
  add_unit_test(test008)
  add_unit_test(test009)
  add_unit_test(test010)
  add_unit_test(test011)
  add_unit_test(test012)
  add_unit_test(test013)
  add_unit_test(test014)
  add_unit_test(test015)
  add_unit_test(test016)
  add_unit_test(test017)
  add_unit_test(test018)
  add_unit_test(test019)
  add_unit_test(test020)
  add_unit_test(test021)
  add_unit_test(test022)
  add_unit_test(test023)
  add_unit_test(test024)
  add_unit_test(test025)
  add_unit_test(test026)
  add_unit_test(test027)
  add_unit_test(test028)
  add_unit_test(test029)
  add_unit_test(test030)
  add_unit_test(test031)
  add_unit_test(test032)
  add_unit_test(test033)
  add_unit_test(test034)
  add_unit_test(test035)
  add_unit_test(test036)
  add_unit_test(test037)
  add_unit_test(test038)
  add_unit_test(test039)
  add_executable(test040 tests/test040.cpp tests/test040b.cpp)
  add_test(NAME text040 CONFIGURATIONS unit COMMAND "${PROJECT_BINARY_DIR}/test040")
  add_unit_test(test041)
  add_unit_test(test042)
  add_unit_test(test043)
  add_unit_test(test044)
  add_unit_test(test045)
  add_unit_test(test046)
  add_unit_test(test047)
  add_unit_test(test048)
  add_unit_test(test049)
  add_unit_test(test050)
  add_unit_test(test051)
  add_unit_test(test052)
  add_unit_test(test053)
  add_unit_test(test054)
  add_unit_test(test055)
  add_unit_test(test056)
  if (HAS_CODECVT)
    add_unit_test(test057)
    add_unit_test(test058)
    add_unit_test(test059)
    add_unit_test(test060)
  endif()
  add_unit_test(test061)
  add_unit_test(test062)
  add_unit_test(test063)
  add_unit_test(test064)
  add_unit_test(test065)
  add_unit_test(test066)
  add_unit_test(test067)
  add_unit_test(test068)
endif()
add_unit_test(test069)
add_unit_test(test070)
add_unit_test(test071)
add_unit_test(test072)
add_unit_test(test073)
add_unit_test(test074)
add_unit_test(test075)
  
# perf tests
add_perf_test(ptest001)
add_perf_test(ptest002)

# Examples
add_executable(ex001 examples/ex001.cpp)
add_executable(ex002 examples/ex002.cpp)
add_executable(ex003 examples/ex003.cpp)
add_executable(ex004 examples/ex004.cpp)
add_executable(ex005 examples/ex005.cpp)
add_executable(ex006 examples/ex006.cpp)
add_executable(ex007 examples/ex007.cpp)
add_executable(ex008 examples/ex008.cpp)
add_executable(ex009 examples/ex009.cpp)

